(function ($) {
  // Registration Form Mobile Accordion
  var onResize = function () {
    if ($(window).width() < 768) {
      // Mobile Only Accordions
      $('.mobile-only').prop('disabled', false);
      $('.form [data-toggle=collapse]').attr('aria-hidden', 'false');

      $('.form .form-check-input').attr('aria-hidden', 'true');
      $('.form .form-check-label').removeAttr('aria-hidden');


      // Registration Page
      $('#registration_form-accordion').on('show.bs.collapse', function (e) {
        $('html,body').stop();
        var el = $(this).find('.card-header');
        $('html, body').animate({
          scrollTop: $(el).offset().top
        }, 0);
      });


      // Form Accordions
      $('.form-accordion .collapse').collapse();

      // Corporate Page 
      $('.corporate-accordion .collapse').addClass('show');
      $('.corporate-accordion [data-toggle=collapse]').removeClass('collapsed');

      // My Account Page
      $('.my-account--card .collapse').collapse();
      $('.my-account--card .card--toggle').prop('disabled', false);

    } else {
      // Mobile Only Accordions
      $('.mobile-only').prop('disabled', true);
      $('.form [data-toggle=collapse]').attr('aria-hidden', 'true');

      // My Account Page
      $('.my-account--card .collapse').collapse('show');
      $('.my-account-card .card--toggle').prop('disabled', true);

      // Form Accordions
      $('.form-accordion .collapse').collapse('show');
      $('.form .form-check-input').removeAttr('aria-hidden');
      $('.form .form-check-label').attr('aria-hidden', 'true');

      // How To Accordion
      $('.how-to-accordion .collapse').addClass('show');

    }
  };


  $(window).resize(onResize);
  $(document).ready(onResize);

  // Open an accordion/collapsable via URL hash

  if (window.location.hash) {
    var panel = window.location.hash;
    setTimeout(function () {
      if ($(panel).length && $(panel).hasClass('collapse')) {
        $('.collapse').hide();
        $('.collapse').removeClass('show').addClass('hide');
        $('.collapse').prev('.card-header').find('.accordion--toggle').addClass('collapsed')
        $('.collapse').prev().find("i:last-child").removeClass('fa-minus').addClass('fa-plus');
        $('.collapse').attr('style', '')
        $(panel).show();
        $(panel).addClass('show').removeClass('hide');
        $(panel).find('.fa-stack-1x').removeClass('fa-plus').addClass('fa-minus');
        $(panel).prev().find("i:last-child").removeClass('fa-plus').addClass('fa-minus');
        $(panel).prev('.card-header').find('.accordion--toggle').removeClass('collapsed');
        $('.collapse').attr('style', '')
      }
    }, 250);
  }


      // Accodion Page Scroll
      $('.accordion').on('shown.bs.collapse', function (e) {
        var offset = $(e.target).prev('.card-header');
        if (offset) {
          $('html,body').stop().animate({
            scrollTop: $(offset).offset().top - 10
          }, 0, 'swing');
        }
      });


  $(".accordion, .my-account--card").on("shown.bs.collapse", function (e) {
    $(e.target).prev().find("i:last-child, em:last-child").removeClass('fa-plus');
    $(e.target).prev().find("i:last-child, em:last-child").addClass('fa-minus');
  });

  $(".accordion, .my-account--card").on("hidden.bs.collapse", function (e) {
    $(e.target).prev().find("i:last-child, em:last-child").removeClass('fa-minus');
    $(e.target).prev().find("i:last-child, em:last-child").addClass('fa-plus');
  });

  $('[data-parent="#accordion-scr-search"]').on('click', function() {
    $('.view-filter-btn-mob .far').toggleClass('fa-plus-circle');
    $('.view-filter-btn-mob .far').toggleClass('fa-minus-circle');
  })
  
})(jQuery);